/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

 /***************************************************************************
  * Name: mp_plugin.h
  *
  * Purpose: plugin base class define for micro player
  *
  * Developer:
  *   wen.gu , 2018-09-03
  *
  * TODO:
  *
  ***************************************************************************/

#ifndef __MP_PLUGIN_H__
#define __MP_PLUGIN_H__


/******************************************************************************
**    INCLUDES
******************************************************************************/

#include <string>

#include "mp_component.h"
#include "mp_types.h"
#include "mp_plugin_manager.h"


/******************************************************************************
**    MACROS
******************************************************************************/

/** plugin header version 
 * note: plugin manager will check this version to jduagement current 
 *       plugin is compatible or not?
 */
#define MP_PLUGIN_HEADER_VER "00.01.00"

/** the name of plugin entry, used by plugin manager */
#define MP_PLUGIN_ENTRY_NAME "_MPPluginEntry"
#define MP_PLUGIN_VER_FUNC_NAME "baseOnPluginHeaderVersion"

/** the entry of plugin, used by plugin implementation */
#define MP_PLUGIN_ENTRY(pluginClass, name, version, author) \
    MPPlugin* _MPPluginEntry(){ \
        MPPlugin* mp = new pluginClass(name, version, author); \
        return mp; \
    } \
    const char* baseOnPluginHeaderVersion(){ \
        return MP_PLUGIN_HEADER_VER; \
    }

/******************************************************************************
**    TYPE DEFINITIONS
******************************************************************************/

/** the type of plugin entry function, used by plugin manager */
typedef MPPlugin* (*pluginEntryFunc_t)();	
typedef const char* (*pluginHdrVerFunc_t)();

/******************************************************************************
**    CLASSES/FUNCTIONS DEFINITIONS
******************************************************************************/

class MPPlugin
{
public:
    MPPlugin(const std::string& name, 
                const std::string& version, 
                const std::string& author)
    :mName(name),
    mVersion(version),
    mAuthor(author)
    {
        /** todo somethings */
    }
    virtual ~MPPlugin() = default;
public:
    virtual const std::string& name() const {return mName;}
    virtual const std::string& version() const {return mVersion;}
    virtual const std::string& author() const {return mAuthor;}

    /** create a component instance(real plugin must implement this API)
     *@parameter

     * [in] param the parameter to request the component
     * [out] comp the instance of component
     *
     *@return
     *   success: M_OK, failed: error code.
     */
    virtual eMPError createComponent(const MPCCreateParam* param,
                                          MPComponent** comp) = 0;
protected:
    std::string mName = "";
    std::string mVersion = "";
    std::string mAuthor = "";
};

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

/** the plugin entry define */
MP_API MPPlugin* _MPPluginEntry();

/** return the version of media plugin header */
MP_API const char* baseOnPluginHeaderVersion();



#endif /** !__MP_PLUGIN_H__*/
